/**
 * @file : 1.cpp
 * @author: fenghuwuyu
 * @version 1.0
 * @mail: 3148107006@qq.com
 * @date: 2021年04月04日 星期日 16时30分00秒
 * @brief:
 */

#include<iostream>

///
// :after constructor means the initial method.
// such as
class my_complex
{
	private:
		double re, im;
	public:
		my_complex(double r, double i) :re{r}, im{i} {};
		my_complex(double r) :re{r}, im{0} {};
		my_complex() :re{0}, im{0} {};

		double get_real() const
		{
			return re;
		};

		void set_real(const double _r)
		{
			re = _r;
		};

		double get_image() const
		{
			return im;
		};

		void set_image(const double _i)
		{
			im = _i;
		};

		///
		// overloading a operator have two method:
		// if the vairable has only one, we use like below
		my_complex& operator+=(const my_complex &z)
		{
			re += z.re;
			im += z.im;
			return *this;
		};
		///
		// if the vairable have more than two, we use like below
		//
		/**
		 * This is a wrong method, because if we overloading a operator in a class as a member function, we can't use more than one vairable, we must use pointer *this to deliver one of the vairable's value.
		 * my_complex operator+(const my_complex& a, const my_complex& b)
		{
			return a+=b;
		};
		*/
		///
		// Then we ought to use friend function like below
		friend my_complex operator+(const my_complex &a, const my_complex &b);

};

my_complex operator+(const my_complex &a, const my_complex &b)
{
	my_complex z1(a.re + b.re, a.im + b.im);
	return z1;
};


